<!-- components/navigation/Breadcrumb.vue -->
<template>
  <el-breadcrumb class="breadcrumb" separator="/">
    <el-breadcrumb-item 
      v-for="(item, index) in breadcrumbItems" 
      :key="index"
      :to="item.path"
    >
      {{ item.title }}
    </el-breadcrumb-item>
  </el-breadcrumb>
</template>

<script setup lang="ts">
// @ts-nocheck
import { ref, computed, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useAppStore } from '@/stores/appStore'

const route = useRoute()
const router = useRouter()
const appStore = useAppStore()

// 计算属性
const breadcrumbItems = computed(() => {
  const matched = route.matched.filter(item => item.meta && item.meta.title)
  const breadcrumbs = matched.map(item => ({
    path: item.path,
    title: item.meta?.title || ''
  }))
  
  // 添加首页
  breadcrumbs.unshift({
    path: '/',
    title: '首页'
  })
  
  return breadcrumbs
})

// 监听路由变化
watch(
  () => route.path,
  () => {
    // 更新页面标题
    const matched = route.matched.filter(item => item.meta && item.meta.title)
    if (matched.length > 0) {
      const last = matched[matched.length - 1]
      appStore.setPageTitle(last.meta?.title as string || '')
    } else {
      appStore.setPageTitle('')
    }
  },
  { immediate: true }
)
</script>

<style scoped>
.breadcrumb {
  font-size: 14px;
}
</style>